package com.example.t470p.facechecktickets;

import android.app.Application;
import android.content.Context;


import com.example.t470p.facechecktickets.Utils.SPUtils;
import com.example.t470p.facechecktickets.Utils.pathUtils;
import com.zhy.http.okhttp.OkHttpUtils;

import java.io.FileInputStream;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;


public class MyApplication extends Application {


    private static Context mAppContext;
    static MyApplication myApplication = new MyApplication();
    public static  String m_Url, m_strGateNo;

    public static MyApplication getMyApplication() {
        return myApplication;
    }


    @Override
    public void onCreate() {
        super.onCreate();
        mAppContext = getApplicationContext();
        //获取配置
        String ConfigPath = pathUtils.getSDPath() + "/config.ini";

        GetConfig(ConfigPath);

        OkHttpClient okHttpClient = new OkHttpClient.Builder()
//                .addInterceptor(new LoggerInterceptor("TAG"))
                .connectTimeout(10000L, TimeUnit.MILLISECONDS)
                .readTimeout(10000L, TimeUnit.MILLISECONDS)
                //其他配置
                .build();

        OkHttpUtils.initClient(okHttpClient);


    }

    public static Context getAppContext() {
        return mAppContext;
    }

    /*
     * 获取配置信息
     */
    public  static boolean GetConfig(String ConfigPath) {
        boolean ret = false;
        try {
            FileInputStream fis = null; // 读
            Properties pp;

            pp = new Properties();
            fis = new FileInputStream(ConfigPath);
            pp.load(fis);

            m_Url = pp.get("SericeUrl").toString();

            m_strGateNo = pp.get("GateNO").toString();// 获取配置文件的Gps_device字段的信息，既它=号后面的数据


        } catch (Exception e) {
            e.printStackTrace();
        }
        return ret;
    }
}